package com.sxj.corejava.code01_线程;

/**
 * @author 石小俊
 * @version 1.0
 * @date 2023年11月14日 18:48
 * 使用线程实现售票功能,共有三个售票窗口,共出售100张票
 */
public class Test03_练习_售票 {

    public static void main(String[] args) {
        TicketRunnable tr = new TicketRunnable();
        // 参数二:表示自定义线程名
        Thread t1 = new Thread(tr,"窗口1");
        Thread t2 = new Thread(tr,"窗口2");
        Thread t3 = new Thread(tr,"窗口3");
        t1.start();
        t2.start();
        t3.start();

//        TicketThread t1 = new TicketThread();
//        TicketThread t2 = new TicketThread();
//        TicketThread t3 = new TicketThread();
//        t1.start();
//        t2.start();
//        t3.start();
    }

}

class TicketRunnable implements Runnable{

    private int num = 100;// 共100张票

    @Override
    public void run() {
        while (num > 0){
            System.out.println(Thread.currentThread().getName()+"正在出票,票号为:"+num--);
        }
    }
}

class TicketThread extends Thread{

    private int num = 100;// 共100张票

    @Override
    public void run() {
        while (num > 0){
            System.out.println(Thread.currentThread().getName()+"正在出票,票号为:"+num--);
        }
    }
}